package haw.pr2.A3.implementations;
import haw.pr2.A3.interfaces.TimeDiff;
import static haw.pr2.A3.implementations.UtilityclassValues.*;
/**
 *
 * @author Fabian Heidorn, Alexander Kaack
 */
class TimeDiffInS extends AbstractScalar<TimeDiff> implements TimeDiff, Comparable<TimeDiff> {

    private final double timeDiffInS;
    
    TimeDiffInS(double timeDiffInS) {
        this.timeDiffInS=timeDiffInS;
    }

    @Override
    public TimeDiff inverse() {
        return new TimeDiffInS(-this.s());
    }

    @Override
    public TimeDiff add(TimeDiff value) {
        return new TimeDiffInS(this.s()+value.s());
    }

    @Override
    public TimeDiff sub(TimeDiff value) {
        return new TimeDiffInS(this.s()-value.s());
    }

    @Override
    public TimeDiff mul(double value) {
        return new TimeDiffInS(this.s()*value);
    }

    @Override
    public TimeDiffInS div(double value) {
        return new TimeDiffInS(this.s()/value);
    }

    @Override
    public double div(TimeDiff value) {
        return this.s()/value.s();
    }

    @Override
    public boolean isZero() {
        return this.equals(ZERO_TIMEDIFF);
    }

    @Override
    public boolean isValid() {
        return true;
    }

    @Override
    public double us() {
        return this.s()*UtilityclassValues.S_IN_US;
    }

    @Override
    public double ms() {
        return this.s()*UtilityclassValues.S_IN_MS;
    }

    @Override
    public double s() {
        return this.timeDiffInS;
    }
    
    @Override
    public double m() {
        return this.s()*UtilityclassValues.S_IN_M;
    }
    
    @Override
    public double h() {
        return this.s()*UtilityclassValues.S_IN_H;
    }
    
    @Override
    public boolean equals(Object obj) {
        if (obj == this) return true;
        if (!(obj instanceof TimeDiff)) return false;
        return this.compareTo((TimeDiff)obj) == 0;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 59 * hash + (int) (Double.doubleToLongBits(this.timeDiffInS) ^ (Double.doubleToLongBits(this.timeDiffInS) >>> 32));
        return hash;
    }
    
    @Override
    public int compareTo(TimeDiff td) {
       return Double.compare(this.s(),td.s());
    }

   // @Override
    public static TimeDiff valueOf(double value) {
        return new TimeDiffInS(value);
    }
    
}

